package com.ruoyi.commissionrecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.commissionrecord.domain.CommissionRecord;
import com.ruoyi.commissionrecord.service.ICommissionRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 返佣记录Controller
 * 
 * @author ruoyi
 * @date 2025-11-20
 */
@RestController
@RequestMapping("/commissionrecord/commissionrecord")
public class CommissionRecordController extends BaseController
{
    @Autowired
    private ICommissionRecordService commissionRecordService;

    /**
     * 查询返佣记录列表
     */
    @PreAuthorize("@ss.hasPermi('commissionrecord:commissionrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommissionRecord commissionRecord)
    {
        startPage();
        List<CommissionRecord> list = commissionRecordService.selectCommissionRecordList(commissionRecord);
        return getDataTable(list);
    }

    /**
     * 导出返佣记录列表
     */
    @PreAuthorize("@ss.hasPermi('commissionrecord:commissionrecord:export')")
    @Log(title = "返佣记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommissionRecord commissionRecord)
    {
        List<CommissionRecord> list = commissionRecordService.selectCommissionRecordList(commissionRecord);
        ExcelUtil<CommissionRecord> util = new ExcelUtil<CommissionRecord>(CommissionRecord.class);
        util.exportExcel(response, list, "返佣记录数据");
    }

    /**
     * 获取返佣记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('commissionrecord:commissionrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commissionRecordService.selectCommissionRecordById(id));
    }

    /**
     * 新增返佣记录
     */
    @PreAuthorize("@ss.hasPermi('commissionrecord:commissionrecord:add')")
    @Log(title = "返佣记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommissionRecord commissionRecord)
    {
        return toAjax(commissionRecordService.insertCommissionRecord(commissionRecord));
    }

    /**
     * 修改返佣记录
     */
    @PreAuthorize("@ss.hasPermi('commissionrecord:commissionrecord:edit')")
    @Log(title = "返佣记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommissionRecord commissionRecord)
    {
        return toAjax(commissionRecordService.updateCommissionRecord(commissionRecord));
    }

    /**
     * 删除返佣记录
     */
    @PreAuthorize("@ss.hasPermi('commissionrecord:commissionrecord:remove')")
    @Log(title = "返佣记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commissionRecordService.deleteCommissionRecordByIds(ids));
    }
}
